package com.lvmama.rhino.common.utils

import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicReference

/**
  * Created by yuanxiaofeng on 2016/10/17.
  */
class SessionIdGenerate {

  self =>
  private val _sessionStorage = new ConcurrentHashMap[String, Long]()

  def sessionStorage = _sessionStorage

  def getSessionId(t: (String, Long)): String = {
    if (!sessionStorage.containsKey(t._1)) {

    }
    ""
  }

  def creatSessionId(deviceToken: String): (String, Long) = {
    val currentTimestamp = System.currentTimeMillis()
    deviceToken -> currentTimestamp
  }

}

object SessionIdGenerate {
  private val LOCK = new Object()

  @transient private val _instance = new AtomicReference[SessionIdGenerate]()

  def instance(): SessionIdGenerate = {
    LOCK.synchronized {
      if (_instance.get() == null) {
        _instance.set(new SessionIdGenerate)
      }
    }
    _instance.get()
  }

}
